package com.briup.utils;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.briup.bean.AlipayBean;
import com.briup.config.AliPayConfig;

import org.springframework.stereotype.Component;

@Component
public class Alipay {

   public  String pay(AlipayBean alipayBean) throws AlipayApiException {

       AlipayClient alipayClient =AliPayConfig.getAlipayClient();
       AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
       // 页面跳转同步通知页面路径
       alipayRequest.setReturnUrl("http://localhost:8080/paySuccess");
       // 服务器异步通知页面路径
       alipayRequest.setNotifyUrl("http://localhost:8080/paySuccess");
       alipayRequest.setBizContent(JSON.toJSONString(alipayBean));
       String result  = alipayClient.pageExecute(alipayRequest).getBody();

       return result;
   }
}
